package ar.edu.itba.it.atlc;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ar.edu.itba.it.atlc.model.Status;
import ar.edu.itba.it.atlc.model.Transition;

public class Main {

	public static void main(String[] args) {
		if (args.length == 0) {
			System.out.println("Debe ingresar un archivo .mt");
		} else if (args.length > 1) {
			System.out.println("Debe ingresar un único archivo .mt");
		} else {
			try {
				BufferedReader br = new BufferedReader(new FileReader(new File(
						args[0])));
				String line;

				Map<Status, List<Transition>> transitions = new HashMap<Status, List<Transition>>();
				Status initial = null;
				if ((line = br.readLine()) != null) {
					initial = Transition.parse(line, transitions);
				}
				while ((line = br.readLine()) != null) {
					Transition.parse(line, transitions);
				}
				new Mt(transitions, initial).start();
			} catch (IOException e) {
				System.out.println("Error al cargar el archivo.");
			} catch (Exception e) {
				System.out.println("\n" + e.getMessage());
			}
		}
	}
}
